#include "stdafx.h"
#include "tinyxml.h"
#include "time.h"
#include <string>
#include <iostream>
#include <fstream>


using namespace std;
int main()
{

	ofstream out( "time.txt" );

	out.clear();
	clock_t start,finish;	
///load
	start=clock();
	
	TiXmlDocument * pDocument = new TiXmlDocument();
	pDocument->LoadFile( "testfile.xml" );
	if ( pDocument == NULL )
	{
		cout << "error in reading..." << endl;
		exit( 0 );
	}
	
	finish=clock();	
	out<< "Loading Time:" << (double)((finish-start)/CLOCKS_PER_SEC) << " secs." << endl;
///load end

///read
	start=clock();
	const TiXmlElement * pXmlIterator = NULL;
	int n = 1;
	do
	{
		for ( int i = 0; i < n; i++ )
		{
			pXmlIterator = pDocument->RootElement()->FirstChildElement();
			if ( pXmlIterator == NULL )
			{
				cout << "error in reading..." << endl;
				exit( 0 );
			}

			while ( pXmlIterator != NULL )
			{
				pXmlIterator = pXmlIterator->NextSiblingElement();
			}
		}
		n = n * 10;	
		finish = clock();
	}while ( (double)((finish-start)/CLOCKS_PER_SEC) < 10 );
	out << "n = " << n << endl;
	out << "reading time" << (double)((finish-start)/CLOCKS_PER_SEC)<< " secs." << endl;
///read end

///visit
	for (int frame_no = 0; frame_no <= 200; frame_no = frame_no + 50)
	{
		start = clock();
		n = 1;
		do
		{			
			for (int i = 0; i < n; i++)
			{
				pXmlIterator = pDocument->RootElement()->FirstChildElement();
				while ( pXmlIterator != NULL )
				{
					if ( atoi(pXmlIterator->Attribute( "no" )) == frame_no )
					{
					break;
					}
					pXmlIterator = pXmlIterator->NextSiblingElement();
				}
				if ( pXmlIterator == NULL )	
				{
					cout << "error in visiting... " << endl;
					exit( 0 );
				}
			}
			finish = clock();
			n = n * 10;
		} while ( (double)((finish-start)/CLOCKS_PER_SEC) < 10 );
		out << "n = " << n << endl;
		out << "time to visit frame " << frame_no << " is " << (double)((finish - start)/CLOCKS_PER_SEC) << "secs" << endl;
	}
///visit end
	out.close();
	delete( pDocument );
	return 0;
}